const { Service } = require("uni-cloud-router");
const uniID = require('uni-id');
const response=require("../utils/response.js");
const db = uniCloud.database({
	spaceId: 'b33db069-91a2-42ff-a831-31fbd5a04b97'
});
const dbCmd = db.command;
const collection=db.collection("uni-id-scores");
module.exports = class ScoresService extends Service {
  async add(){
		
  }
  async list(){
  	const { ctx, service } = this;
		const year=(new Date()).getFullYear()
		const start_time=(new Date(year-1,0,1)).getTime()
  	const res=await collection.where({
  		user_id:ctx.uid,
			create_date:dbCmd.gt(start_time)
  	}).orderBy('create_date','desc').get();
  	if(res.affectedDocs>=0){
  		return response.success(res.data);
  	}else{
  		return response.fail('查询失败');
  	}
  }
  async delete(){
		const ctx=this.ctx
  	const res=await collection.where({
			_id: dbCmd.in(ctx.data.ids)
		}).remove();
		if(res.affectedDocs>=0){
			return response.success(res.data);
		}else{
			return response.fail('删除失败');
		}
  }
};